feat: add native AOT support - #6
Conversation
Code ReviewPR #6: feat: add native AOT support SummaryThis PR adds comprehensive Native AOT support to AWS.AgentCore, introducing source-generated JSON serialization and AOT-safe strongly-typed overloads for both non-streaming and streaming scenarios. The approach is well-designed: reflection-based overloads are preserved for non-AOT users and properly annotated with [RequiresUnreferencedCode]/[RequiresDynamicCode], while new overloads accepting JsonTypeInfo enable zero-warning AOT publishing. The source generator is updated to emit the appropriate overload based on the new JsonContext property. Two sample apps demonstrate both programming models. Overall this is a high-quality PR with thorough documentation, good test coverage, and a clean API design. A few issues warrant attention before merge. Important Issues - Should Fix
Minor Issues
Positive Notes
RecommendationRequest changes - please address the important issues listed above. |
|
approved assuming double check the comment about the |
217387a to
a4c0065
Compare
Issue #, if available:
DOTNET-8612
Description of changes
Makes the library fully NativeAOT-compatible across both programming models (extensions and annotations). Users can now publish agents as self-contained native binaries with zero trimmer/AOT warnings.
Changes
Library (
AWS.AgentCore)IsAotCompatible=trueto the projectAgentCoreJsonContext— source-generated JSON serialization for all internal response types (ping, SSE chunks, error responses), eliminating runtime reflection for JSONJsonTypeInfo<TRequest>for explicit source-generated deserialization:MapAgentCore<TRequest>(handler, requestTypeInfo, pingHandler?)— non-streamingMapAgentCoreStreaming<TRequest>(handler, requestTypeInfo, pingHandler?)— SSE streamingJsonTypeInfofor non-AOT usage (marked with[RequiresUnreferencedCode]/[RequiresDynamicCode])Delegate-based overload annotated with[RequiresUnreferencedCode]/[RequiresDynamicCode]JsonTypeInfooverloads and the[AgentCoreHandler]source generator as AOT alternatives[UnconditionalSuppressMessage]onMapPingEndpoint(verified safe — only uses library-owned types with source-generatedJsonTypeInfo)Source Generator (
AWS.AgentCore.SourceGenerator)MapAgentCore<TRequest>/MapAgentCoreStreaming<TRequest>calls instead of theDelegate-based overloadIServiceProvider(notapp.Services) matching the strongly-typed overload signatureJsonContextproperty to[AgentCoreHandler]— when set, the generator emits theJsonTypeInfoparameter for fully AOT-safe deserializationJsonContextis not set, the generator emits the reflection-based overload (works fine for non-AOT projects)GeneratorTestHelperstubs to includeJsonContextproperty andJsonSerializerContext/JsonSerializableAttributetypesSample Apps
NativeAotExtensions— extensions model withPublishAot,JsonTypeInfo, and user-definedAppJsonContextNativeAotAnnotations— annotations model withPublishAot,[AgentCoreHandler(JsonContext = typeof(AppJsonContext))], and AOT-optimized Dockerfile (runtime-depsbase,clangfor AOT linker, native binary entrypoint)Tests
WithJsonContexttest case)Overload matrix
MapAgentCore<T>(Delegate)MapAgentCore<T>(Func<...Task<string>>)MapAgentCore<T>(Func<...Task<string>>, JsonTypeInfo<T>)MapAgentCoreStreaming<T>(Func<...IAsyncEnumerable<string>>)MapAgentCoreStreaming<T>(Func<...IAsyncEnumerable<string>>, JsonTypeInfo<T>)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.